package logic

import (
	"context"
	"order-pro/model"

	"order-pro/prorpc/internal/svc"
	"order-pro/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *prorpc.GoodAddRequest) (*prorpc.GoodAddResponse, error) {
	// todo: add your logic here and delete this line
	var good model.Good

	goods := model.Good{
		Name:   in.Name,
		Price:  float64(in.Price),
		Status: int(in.Status),
		Stock:  int(in.Stock),
		Img:    in.Img,
	}
	model.DB.Create(&goods)

	return &prorpc.GoodAddResponse{
		GoodID: int64(good.ID),
	}, nil
}
